package com.itheima.UDP.组播广播;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ServiceDemo {
    public static void main(String[] args) throws IOException {
        MulticastSocket ms = new MulticastSocket(10000);
        //把当前计算机绑定一个组播地址，表示添加到这一组中
        ms.joinGroup(InetAddress.getByName("224.1.1.0"));
        while (true) {
            DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);

            ms.receive(dp);

            byte[] data = dp.getData();
            int length = dp.getLength();
            System.out.println(new String(data, 0, length));
        }

    }
}
